import { EnumSchema } from '@/utils/common/types';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** 设备变量状态枚举 */
export enum DeviceVaribaleStatusEnum {
  /** 未知 */
  Unknown = 0,
  /** 良好 */
  Good = 1,
  /** 地址错误 */
  AddressError = 2,
  /** 方法错误 */
  MethodError = 3,
  /** 表达式错误 */
  ExpressionError = 4,
  /** 损坏 */
  Bad = 99,
}

/** 设备变量状态实体 */
export class DeviceVaribaleStatusEntity {
  /** 设备变量状态 */
  VaribaleStatus: DeviceVaribaleStatusEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(varibaleStatus: DeviceVaribaleStatusEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.VaribaleStatus = varibaleStatus;
    this.Color = color;
    switch (varibaleStatus) {
      case DeviceVaribaleStatusEnum.Unknown:
        // this.Display = '未知';
        this.Display = t('iot.enum.deviceVaribaleStatus.unknown');
        this.Color = this.Color ? this.Color : PresetColorEnum.Default;
        break;
      case DeviceVaribaleStatusEnum.Good:
        // this.Display = '良好';
        this.Display = t('iot.enum.deviceVaribaleStatus.good');
        this.Color = this.Color ? this.Color : '#228B22';
        break;
      case DeviceVaribaleStatusEnum.AddressError:
        // this.Display = '地址错误';
        this.Display = t('iot.enum.deviceVaribaleStatus.addressError');
        this.Color = this.Color ? this.Color : '#FF5809';
        break;
      case DeviceVaribaleStatusEnum.MethodError:
        // this.Display = '方法错误';
        this.Display = t('iot.enum.deviceVaribaleStatus.methodError');
        this.Color = this.Color ? this.Color : '#F75000';
        break;
      case DeviceVaribaleStatusEnum.ExpressionError:
        // this.Display = '表达式错误';
        this.Display = t('iot.enum.deviceVaribaleStatus.expressionError');
        this.Color = this.Color ? this.Color : '#EE722E';
        break;
      case DeviceVaribaleStatusEnum.Bad:
        // this.Display = '损坏';
        this.Display = t('iot.enum.deviceVaribaleStatus.bad');
        this.Color = this.Color ? this.Color : '#DC143C';
        break;
    }
  }
}

//#region 获取设备变量状态枚举架构
/**
 * 获取设备变量状态枚举架构
 */
export function getDeviceVaribaleStatusEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: DeviceVaribaleStatusEntity[] = [
    new DeviceVaribaleStatusEntity(DeviceVaribaleStatusEnum.Unknown),
    new DeviceVaribaleStatusEntity(DeviceVaribaleStatusEnum.Good),
    new DeviceVaribaleStatusEntity(DeviceVaribaleStatusEnum.AddressError),
    new DeviceVaribaleStatusEntity(DeviceVaribaleStatusEnum.MethodError),
    new DeviceVaribaleStatusEntity(DeviceVaribaleStatusEnum.ExpressionError),
    new DeviceVaribaleStatusEntity(DeviceVaribaleStatusEnum.Bad),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.VaribaleStatus as number,
      label: item.Display,
      value: item.VaribaleStatus as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
